<?php
/**
 * name 刘杨
 * 用户
 */
namespace backend\controllers;
use Yii;
use backend\models\Position;
use yii\data\Pagination;
class PositionController extends \yii\web\Controller
{
	public $layout = 'admin_main';
    function init()
    {
        $session = Yii::$app->session;
        if(empty($session->get('admin_user')))
        {
            $this->redirect('?w=login/login');
        }
    }
	//展示发布
    public function actionIndex()
    {
    	$page = Yii::$app->request->get('page')?Yii::$app->request->get('page'):'1';
    	$Position = Position::find();
        $pagination = new Pagination([
            'defaultPageSize' => 7,
            'totalCount' => $Position->count(),
        ]);
        $data = $Position->offset($pagination->offset)
        ->limit($pagination->limit)
        ->orderBy('id desc')
        ->asArray()
        ->all();
        $User['data'] = $data;
        $User['page'] = $page;
        $User['pagination'] = $pagination;
        return $this->render('index',$User);
    }
    //审核
    public function actionState()
    {
    	$state = Yii::$app->request->get('state');
    	$id = Yii::$app->request->get('id');
    	$Position = Position::findOne($id);
    	$Position->pos_state = $state;
    	if($Position->save())
    	{
    		exit(json_encode(array('error'=>1)));
    	}else
    	{
    		exit(json_encode(array('error'=>0,'msg'=>'审核失败')));
    	}
    }
}
